<?php
namespace app\madmin\controller;
use app\madmin\model\WechatReplyModel;

/**
 * 图文控制器
 * @author  黄明杰 vx:HMJ125855
 * @version 20190201
 */
class WechatReply extends PublicBase{

	# 图文列表方法
    public function showList(){
        $WechatReply = new WechatReplyModel;

        $Where = $this->getFormWhere();

        $key_type = input('param.key_type');
        if(!empty($key_type)){
            $Where['key_type'] = $key_type;
        }
        $this->assign('key_type', $key_type);

        $Lists = $WechatReply->mList($Where, '*', config('CNF_LISTPAGE'));

        return $this->fetch('WechatReply/showList', [
            'Lists' => $Lists
        ]);
    }

    # 图文新增方法
    public function showAdd(){
        $WechatReply = new WechatReplyModel;

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $WechatReply->mAdd($Param);

            $this->WechatMessageLists($Param['key_name']);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            return $this->fetch('WechatReply/showAdd', [
                'Info'  => Null
            ]);
        }
    }

    # 图文更新方法
    public function showEdit(){
        $WechatReply = new WechatReplyModel;

    	$ID = input('param.id');

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $WechatReply->mEdit(['key_id'=>$ID], $Param);

            $this->WechatMessageLists($Param['key_name']);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            $Info = $WechatReply->mInfo(['key_id'=>$ID]);

            if(empty($Info)){
                $this->ShowData(2, lang('XtCwCxCw'));
            }

            return $this->fetch('WechatReply/showAdd', [
                'Info'  => $Info
            ]);
        }
    }

    # 图文删除方法
    public function showDel(){
        if(request()->isPost()){
            $WechatReply = new WechatReplyModel;

            $ID = input('post.id');

            $Back = $WechatReply->mDel(['key_id'=>$ID]);

            $this->WechatMessageLists($Param['key_name']);

            $this->ShowData($Back['code'], $Back['msgs']);
        }
    }

}